<template>
  <el-dialog :visible.sync="dialogVisible" :before-close="cancel" width="40%">
    <template slot="title">
      <span >新建任务</span>
    </template>
    <el-form
    ref="refForm"
    :rules="refRule"
    :disabled="loading"
    :model="form" class="demo-form-inline">
    <el-form-item label="游戏平台" prop="gamePlatform" width="300px" >
            <el-select v-model="form.gamePlatform " >
              <el-option
                v-for="item in GAME_PLATFORM_LIST.filter((item)=>{return item.type.includes('taskDelete')})"
                :label="item.title"
                :key="item.value"
                :value="item.value"
              ></el-option>
            </el-select>
    </el-form-item>
     <el-form-item label="删除方式" prop="deleteType" width="300px" >
        <el-select v-model="form.deleteType " >
          <el-option
            v-for="item in DELETE_TYPE_LIST"
            :label="item.title"
            :key="item.value"
            :value="item.value"
          ></el-option>
        </el-select>
    </el-form-item>
     <el-form-item prop="index" label="索引日期" style="display:flex" v-if="form.deleteType==1">
      <el-input   v-model.trim="form.index" maxlength="200">
      </el-input>
    </el-form-item>
    <el-form-item label="删除时间" prop="time" width="300px" v-if="form.deleteType==2">
         <el-date-picker
          class="date-picker-box"
          v-model="form.time"
          type="datetimerange"
          align="right"

          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
          :default-time="['00:00:00', '23:59:59']"

          >
      </el-date-picker>
    </el-form-item>
    <el-form-item prop="betNoArray" label="注单号" v-if="form.deleteType==1">
      <el-input type="textarea"  rows="3" v-model.trim="form.betNoArray" placeholder="支持输入多个单号，多个单号用逗号分隔">
      </el-input>
    </el-form-item>
    <div style="text-align:right">
      <el-button class="filter-item"
                 @click="cancel">取消
      </el-button>
      <el-button class="filter-item" type="primary" :loading="!istap"
                 @click="toSave">确认
      </el-button>
    </div>
  </el-form>

</el-dialog>
</template>
<script>
import {
  form, grid, factory, pickerOption,
} from '@/build';
import { jobListAdd } from '@/services/api/gameDataManage';
import { GAME_PLATFORM_LIST, DELETE_TYPE_LIST } from '../data';

export default {
  name: 'add-account-dialog',
  mixins: [form, grid, factory],
  pickerOption,
  props: ['dialogVisible'],

  data() {
    return {
      GAME_PLATFORM_LIST,
      DELETE_TYPE_LIST,
      istap: true,
      form: {
        time: [
          moment().format('YYYY-MM-DD 00:00:00'),
          moment().format('YYYY-MM-DD 23:59:59'),
        ],
        betNoArray: '',
        index: '',
        gamePlatform: undefined,
        deleteType: undefined,
        startTime: undefined,
        endTime: undefined,
        remark: '',
      },
      refRule: {
        betNoArray: [
          { required: true, message: '注单号不能为空', trigger: 'change' },
        ],
        time: [
          { required: true, message: '日期为必选项', trigger: 'change' },
        ],
        deleteType: [
          { required: true, message: '删除方式为必选项', trigger: 'change' },
        ],
        gamePlatform: [
          { required: true, message: '游戏平台为必选项', trigger: 'change' },
        ],
        index: [
          { required: true, message: '索引日期不能为空', trigger: 'blur' },
        ],
      },
    };
  },

  filters: {

  },

  methods: {
    appSuccessCBK(val) {
      console.log(`文件=====${JSON.stringify(val)}`);
    },
    cancel() {
      this.$emit('cancel');
    },
    toSave() {
      if (!this.istap) return;
      this.$refs.refForm.validate((valid) => {
        if (valid) {
          this.istap = false;
          this.doSave({ action: 'saveForm' });
        } else {
          return false;
        }
      });
    },

  },
  mounted() {
    this.bindSave(jobListAdd, 'saveForm', 'form', {
      beforeSend: (data) => {
        if (data.time) {
          data.startTime = data.time[0];
          data.endTime = data.time[1];
        }
        return data;
      },
      callback: ([result, data]) => {
        this.cancel();
        this.istap = true;
        if (result) {
          this.$parent.gridSearch();
          this.$notify({
            title: '保存成功',
            type: 'success',
            duration: 2000,
          });
        } else {
          this.$notify({
            title: `保存失败.${data && data.message}`,
            type: 'error',
            duration: 2000,
          });
        }
      },
    });
  },

};
</script>

<style lang="scss" scoped>

</style>
